package com.yun.algorithmproblem.leetcode;

public class Leetcode2012 {


    public int sumOfBeauties(int[] nums) {
        int n = nums.length;
        int[] leftMaxNums = new int[n];
        int[] rightMinNums = new int[n];
        int leftMax = 0, rightMin = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            leftMaxNums[i] = leftMax;
            leftMax = Math.max(leftMax, nums[i]);
        }
        for (int i = nums.length - 1; i >= 0; i--) {
            rightMinNums[i] = rightMin;
            rightMin = Math.min(rightMin, nums[i]);
        }
        int ans = 0;
        for (int i = 1; i < nums.length - 1; i++) {
            if (leftMaxNums[i] < nums[i] && nums[i] < rightMinNums[i]) {
                ans += 2;
            } else if (nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) {
                ans++;
            }
        }
        return ans;
    }
}
